#!/bin/sh
#
# DracoPKG
#
# Copyright 2008 Ole Andre Rodlie <olear@dracolinux.org>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mkdir -p $DRACOSRC_PKG/usr/share/draco/{dp_conf,dp_func} || exit 1
mkdir -p $DRACOSRC_PKG/sbin || exit 1
mkdir -p $DRACOSRC_PKG/etc || exit 1

#cp -a $DRACOSRC_PKG_SRC_DIR/overlay/* $DRACOSRC_PKG/usr/share/draco/dp_overlay/ || exit 1
#chown root:root -R $DRACOSRC_PKG/usr/share/draco/dp_overlay/* || exit 1
#chmod 644 -R $DRACOSRC_PKG/usr/share/draco/dp_overlay/* || exit 1

cp $DRACOSRC_PKG_SRC_DIR/conf/*.conf $DRACOSRC_PKG/usr/share/draco/dp_conf/ || exit 1
cp $DRACOSRC_PKG_SRC_DIR/func/*.func $DRACOSRC_PKG/usr/share/draco/dp_func/ || exit 1
chown root:root $DRACOSRC_PKG/usr/share/draco/{dp_conf,dp_func}/* || exit 1
chmod 644 $DRACOSRC_PKG/usr/share/draco/{dp_conf,dp_func}/* || exit 1

cat $DRACOSRC_PKG_SRC_DIR/scripts/dracopkg.sh > $DRACOSRC_PKG/sbin/dracopkg || exit 1
#cat $DRACOSRC_PKG_SRC_DIR/scripts/netconfig > $DRACOSRC_PKG/sbin/netconfig || exit 1
#cat $DRACOSRC_PKG_SRC_DIR/scripts/rescan-scsi-bus > $DRACOSRC_PKG/sbin/rescan-scsi-bus || exit 1

cat $DRACOSRC_PKG_SRC_DIR/dp.conf > $DRACOSRC_PKG/etc/dp.conf.new || exit 1
chmod 644 $DRACOSRC_PKG/etc/dp.conf.new

( cd $DRACOSRC_PKG/sbin ; ln -s dracopkg dp )
chmod 755 $DRACOSRC_PKG/sbin/*

#mkdir -p $DRACOSRC_PKG/var/log/setup
#cat $DRACOSRC_PKG_SRC_DIR/setup/setup.draco > $DRACOSRC_PKG/var/log/setup/setup.draco || exit 1
#cat $DRACOSRC_PKG_SRC_DIR/setup/setup.netconfig > $DRACOSRC_PKG/var/log/setup/setup.netconfig || exit 1
#cat $DRACOSRC_PKG_SRC_DIR/setup/setup.services > $DRACOSRC_PKG/var/log/setup/setup.services || exit 1
#chmod 755 $DRACOSRC_PKG/var/log/setup/*

#echo "Draco GNU/Linux ${DRACOSRC_PKG_VERSION}" > $DRACOSRC_PKG/etc/draco-version || exit
#cat $DRACOSRC_PKG_SRC_DIR/motd > $DRACOSRC_PKG/etc/motd.new || exit 1
#echo > $DRACOSRC_PKG/etc/issue || exit 1 
#echo "Draco GNU/Linux ${DRACOSRC_PKG_VERSION} Kernel \r (\l)" >> $DRACOSRC_PKG/etc/issue || exit 1
#echo >> $DRACOSRC_PKG/etc/issue || exit 1

# Legacy crap, remove in 0.3.2
mkdir -p $DRACOSRC_PKG/etc/dp/pkgtools
ln -sf /sbin/installpkg $DRACOSRC_PKG/etc/dp/pkgtools/installpkg
ln -sf /sbin/upgradepkg $DRACOSRC_PKG/etc/dp/pkgtools/upgradepkg
ln -sf /sbin/removepkg $DRACOSRC_PKG/etc/dp/pkgtools/removepkg




